
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>final、finally、finalize 的区别 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>final、finally、finalize 的区别 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">在Java中，`final`关键字可以修饰哪些元素？分别有什么作用？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`final`关键字可以修饰类、方法和变量。当修饰类时，该类不能被继承；当修饰方法时，该方法不能被子类重写；当修饰变量时，该变量的值在初始化后不能再改变。</div>
          </div>
          <div class="card-source">来源: 1. final 关键字</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">`finally`块在Java异常处理中的主要用途是什么？它的代码在什么情况下会执行？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`finally`块通常用于关闭资源，如文件流、数据库连接等，以确保这些资源得到正确释放。无论`try`块中是否抛出异常，`finally`块中的代码都会被执行。</div>
          </div>
          <div class="card-source">来源: 2. finally 块</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">什么是`finalize`方法？为什么现在不推荐使用它？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`finalize`是`Object`类中的一个方法，用于在对象被垃圾回收器回收前提供资源释放的最后机会。由于其调用时间不确定且效率低下，可能导致资源释放延迟，因此它被认为是不推荐使用的。</div>
          </div>
          <div class="card-source">来源: 3. finalize 方法</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">概念</div>
          <div class="card-question">请简要区分`final`、`finally`和`finalize`这三个术语的核心作用。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">概念</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`final`是一个关键字，用于防止类、方法或变量被更改，保证程序的稳定性和安全性。`finally`是用于异常处理的关键字，确保其中的代码块（如资源释放）总能被执行。`finalize`是`Object`类的一个方法，用于对象被垃圾回收前的清理操作，但已不推荐使用。</div>
          </div>
          <div class="card-source">来源: 文档开篇及各章节总结</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">如果在`try`或`catch`块中遇到了`return`语句，`finally`块还会执行吗？如果会，执行顺序是怎样的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">会执行。如果在`try`块或`catch`块中执行了`return`语句，`finally`块仍然会在方法返回之前执行。</div>
          </div>
          <div class="card-source">来源: 2. finally 块</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">文档中提到`finalize`方法是一种过时的用法，那么从Java 9开始，有什么更好的替代方案？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Java 9 以后引入的`Cleaner`类提供了更好的替代方案，用于替代`finalize`的功能。</div>
          </div>
          <div class="card-source">来源: 3. finalize 方法</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
